package executors;
import objects.Command;
import objects.Result;
import objects.SortedEventList;


/**
 * This is the class handle different command retrieved from Controller.
 * 
 * @author JJP
 */
public class CommandHandler {
	private static SortedEventList openTasks = new SortedEventList();
    private static SortedEventList completeTasks=new SortedEventList();

	/**
	 * =================================================================== TOP
	 * LEVEL
	 * ====================================================================
	 */
	public static Result executeCommand(Command command) {
		COMMAND_TYPE commandType = COMMAND_TYPE.determineCommandType(command);
		return excute(commandType, command);
	}

	/**
	 * ===================================================================
	 * SECOND LEVEL
	 * ====================================================================
	 */
	private static Result excute(COMMAND_TYPE commandType, Command command) {
		// TODO Auto-generated method stub
		switch (commandType) {
		case ADD:
			 return AddExecutor.execute(command, openTasks,completeTasks);
		case SUBADD:
			return SubAddExecutor.execute(command, openTasks,completeTasks);
		case SORT:
			return SortExecutor.execute(command, openTasks,completeTasks);
		case SET:
			return EditExecutor.execute(command, openTasks,completeTasks);
		case DELETE:
			return DeleteExecutor.execute(command, openTasks,completeTasks);
		case SEARCH:
			return SearchExecutor.execute(command, openTasks,completeTasks);
		case GET:
			return GetExecutor.execute(command, openTasks,completeTasks);
		case WRITE_FILE:
			return WriteExecutor.execute(command, openTasks,completeTasks);
		case READ_FILE:
			return ReadExecutor.execute(command, openTasks,completeTasks);
		case EXIT:
			return ExitExecutor.execute(command, openTasks,completeTasks);
		default:
			throw new Error("Unrecognized command type");
		}
	}

}